package com.demo.application;

import java.util.Date;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@ControllerAdvice
public class AppInitBinder extends ResponseEntityExceptionHandler {
    /**
     * controller form 的日期类型转换
     * @param binder
     * @param request
     */
    @InitBinder
    public void registerCustomEditors(WebDataBinder binder, WebRequest request) {
        binder.registerCustomEditor(Date.class, new JacksonDateEditor(AppSetting.getDefaultTimeZone(), true));
    }
}
